<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="店铺号" prop="storeNumber">
        <el-input
          v-model="queryParams.storeNumber"
          placeholder="请输入店铺号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省份" prop="province">
        <el-input
          v-model="queryParams.province"
          placeholder="请输入省份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区/县" prop="districts">
        <el-input
          v-model="queryParams.districts"
          placeholder="请输入区/县"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入店铺地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺名称" prop="storeName">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺类型" prop="storeType">
        <el-select v-model="queryParams.storeType" placeholder="请选择店铺类型" clearable>
          <el-option
            v-for="dict in dict.type.store_adidas_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="店铺品牌" prop="storeBrand">
        <el-select v-model="queryParams.storeBrand" placeholder="请选择店铺品牌" clearable>
          <el-option
            v-for="dict in dict.type.store_adidas_brand"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="店铺状态" prop="storeStatus">
        <el-select v-model="queryParams.storeStatus" placeholder="请选择店铺状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:workOrderStoreAdidas:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:workOrderStoreAdidas:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:workOrderStoreAdidas:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:workOrderStoreAdidas:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="workOrderStoreAdidasList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="店铺id" align="center" prop="storeId" v-if="false"/>
      <el-table-column label="店铺" align="center" prop="storeNumber"  width="350" >
        <template slot-scope="scope">
          <span>{{ scope.row.storeNumber }} / {{ scope.row.storeName}}/ {{ scope.row.storeBrand}}/ {{ scope.row.storeType}}/ {{ scope.row.manageArea}}</span>
        </template>
        </el-table-column>
      
      <el-table-column label="开店日期" align="center" prop="openDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.openDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="店铺联系人" align="center" prop="storeContacts" width="200">
        <template slot-scope="scope">
          <span>{{ scope.row.storeContacts }} / {{ scope.row.storeContactNumber}}/ {{ scope.row.storeEmail}}</span>
        </template>
      </el-table-column>
      <el-table-column label="店铺状态" align="center" prop="storeStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.storeStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="店铺定位" align="center" prop="storeGps" />
      <el-table-column label="地址" align="center" prop="province"  width="500">
        <template slot-scope="scope">
          <span>{{ scope.row.province }} / {{ scope.row.city}}/ {{ scope.row.districts}}/ {{ scope.row.address}}</span>
        </template>
        </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:workOrderStoreAdidas:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:workOrderStoreAdidas:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改工单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="店铺号" prop="storeNumber">
          <el-input v-model="form.storeNumber" placeholder="请输入店铺号" />
        </el-form-item>
        <el-form-item label="省份" prop="province">
          <el-input v-model="form.province" placeholder="请输入省份" />
        </el-form-item>
        <el-form-item label="城市" prop="city">
          <el-input v-model="form.city" placeholder="请输入城市" />
        </el-form-item>
        <el-form-item label="区/县" prop="districts">
          <el-input v-model="form.districts" placeholder="请输入区/县" />
        </el-form-item>
        <el-form-item label="店铺地址" prop="address">
          <el-input v-model="form.address" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所属管理大区" prop="manageArea">
          <el-input v-model="form.manageArea" placeholder="请输入所属管理大区" />
        </el-form-item>
        <el-form-item label="店铺名称" prop="storeName">
          <el-input v-model="form.storeName" placeholder="请输入店铺名称" />
        </el-form-item>
        <el-form-item label="店铺类型" prop="storeType">
          <el-select v-model="form.storeType" placeholder="请选择店铺类型">
            <el-option
              v-for="dict in dict.type.store_adidas_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="店铺品牌" prop="storeBrand">
          <el-select v-model="form.storeBrand" placeholder="请选择店铺品牌">
            <el-option
              v-for="dict in dict.type.store_adidas_brand"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开店日期" prop="openDate">
          <el-date-picker clearable
            v-model="form.openDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开店日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="店铺联系人" prop="storeContacts">
          <el-input v-model="form.storeContacts" placeholder="请输入店铺联系人" />
        </el-form-item>
        <el-form-item label="店铺联系电话" prop="storeContactNumber">
          <el-input v-model="form.storeContactNumber" placeholder="请输入店铺联系电话" />
        </el-form-item>
        <el-form-item label="店铺邮箱" prop="storeEmail">
          <el-input v-model="form.storeEmail" placeholder="请输入店铺邮箱" />
        </el-form-item>
        <el-form-item label="店铺状态" prop="storeStatus">
          <el-radio-group v-model="form.storeStatus">
            <el-radio
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="店铺定位" prop="storeGps">
          <el-input v-model="form.storeGps" placeholder="请输入店铺定位" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWorkOrderStoreAdidas, getWorkOrderStoreAdidas, delWorkOrderStoreAdidas, addWorkOrderStoreAdidas, updateWorkOrderStoreAdidas } from "@/api/system/workOrderStoreAdidas";

export default {
  name: "WorkOrderStoreAdidas",
  dicts: ['store_adidas_type', 'store_adidas_brand', 'sys_normal_disable'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工单表格数据
      workOrderStoreAdidasList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeNumber: undefined,
        province: undefined,
        city: undefined,
        districts: undefined,
        address: undefined,
        storeName: undefined,
        storeType: undefined,
        storeBrand: undefined,
        storeStatus: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        storeId: [
          { required: true, message: "店铺id不能为空", trigger: "blur" }
        ],
        storeNumber: [
          { required: true, message: "店铺号不能为空", trigger: "blur" }
        ],
        province: [
          { required: true, message: "省份不能为空", trigger: "blur" }
        ],
        city: [
          { required: true, message: "城市不能为空", trigger: "blur" }
        ],
        districts: [
          { required: true, message: "区/县不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "店铺地址不能为空", trigger: "blur" }
        ],
        manageArea:[
        { required: true, message: "所属管理大区不能为空", trigger: "blur" }
        ],
        storeName: [
          { required: true, message: "店铺名称不能为空", trigger: "blur" }
        ],
        storeType: [
          { required: true, message: "店铺类型不能为空", trigger: "change" }
        ],
        storeBrand: [
          { required: true, message: "店铺品牌不能为空", trigger: "change" }
        ],
        openDate: [
          { required: true, message: "开店日期不能为空", trigger: "blur" }
        ],
        storeContacts: [
          { required: true, message: "店铺联系人不能为空", trigger: "blur" }
        ],
        storeContactNumber: [
          { required: true, message: "店铺联系电话不能为空", trigger: "blur" }
        ],
        storeEmail: [
          { required: true, message: "店铺邮箱不能为空", trigger: "blur" }
        ],
        storeStatus: [
          { required: true, message: "店铺状态不能为空", trigger: "change" }
        ],
        storeGps: [
          { required: true, message: "店铺定位不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询工单列表 */
    getList() {
      this.loading = true;
      listWorkOrderStoreAdidas(this.queryParams).then(response => {
        this.workOrderStoreAdidasList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        storeId: undefined,
        storeNumber: undefined,
        province: undefined,
        city: undefined,
        districts: undefined,
        address: undefined,
        storeName: undefined,
        storeType: undefined,
        storeBrand: undefined,
        openDate: undefined,
        storeContacts: undefined,
        storeContactNumber: undefined,
        storeEmail: undefined,
        storeStatus: undefined,
        storeGps: undefined,
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        remark: undefined,
        manageArea: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.storeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加工单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const storeId = row.storeId || this.ids
      getWorkOrderStoreAdidas(storeId).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改工单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.storeId != null) {
            updateWorkOrderStoreAdidas(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addWorkOrderStoreAdidas(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const storeIds = row.storeId || this.ids;
      this.$modal.confirm('是否确认删除工单编号为"' + storeIds + '"的数据项？').then(() => {
        this.loading = true;
        return delWorkOrderStoreAdidas(storeIds);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/workOrderStoreAdidas/export', {
        ...this.queryParams
      }, `workOrderStoreAdidas_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
